export function useHistory() {
  const push = ({ path, params = {}, query = {}, data = {} }) => {
    history.pushState({ ...data, goBack: true }, '', `${path}/${__combineParams(params)}${__combineQuery(query)}`)
  }

  const replace = ({ path, params = {}, query = {}, data = {} }) =>
    history.replaceState({ ...data, goBack: true }, '', `${path}/${__combineParams(params)}${__combineQuery(query)}`)

  const __combineParams = (params) => Object.values(params).join('/')

  const __combineQuery = (query) => {
    if (Object.keys(query).length === 0) return ''
    return Object.entries(query).reduce((acc, [key, value]) => `${acc}&${key}=${value}`, '?')
  }

  return { push, replace }
}
